package com.example.socialcontactapp.controller;

import com.example.socialcontactapp.service.ChatService;
import com.example.socialcontactapp.utils.R;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: ruohao
 * @Date: 2022/8/2
 **/
@RestController
@RequestMapping("/chat")
public class ChatController {
    @Resource
    private ChatService chatService;

    @RequestMapping("/getChat")
    public R getChat(Long sender, Long receiver, Long before, Long after) {
        try {
           return chatService.getChats(sender, receiver, before, after);
        } catch (Exception e) {
            return R.error().data("msg", "内部错误");
        }
    }

    @RequestMapping("/sendChat")
    public R sendChat(Long sender, Long receiver, String content) {
        try {
            return chatService.getChats≈(sender, receiver, before, after);
        } catch (Exception e) {
            return R.error().data("msg", "内部错误");
        }
    }
}
